package muilty_thread.atomic;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceTest {

    public static void main(String[] args) {
        Person p1 = new Person(1);
        Person p2 = new Person(12);
        AtomicReference<Person> reference = new AtomicReference<>(p1);
        System.out.println(reference.compareAndSet(p1, p2));
        System.out.println(reference.get());
        System.out.println(reference.get()==p2);
        System.out.println(reference.get()==p1);

    }
}


class Person {
    volatile long id;
    public Person(long id) {
        this.id = id;
    }
    public String toString() {
        return "id:"+id;
    }
}